import { Component } from '@angular/core';

import { SingleInputModalService } from '@share/base/component';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'app-single-input-modal',
  templateUrl: './single-input-modal.component.html',
  providers: [SingleInputModalService]
})
export class SingleInputModalComponent {
  constructor(private singleInputModalSrc: SingleInputModalService, private messageSrc: NzMessageService) {}

  open(): void {
    const modal = this.singleInputModalSrc.open('默认窗口');
    modal.afterClose.subscribe(data => {
      if (data != undefined) {
        this.messageSrc.success(`ok:${data}`);
      } else {
        this.messageSrc.info(`cancel:${data}`);
      }
    });
  }

  openOption(): void {
    const modal = this.singleInputModalSrc.open('自定义窗口', { minlength: 6, maxlength: 12, value: '初始值' });
    modal.afterClose.subscribe(data => {
      if (data != undefined) {
        this.messageSrc.success(`ok:${data}`);
      } else {
        this.messageSrc.info(`cancel:${data}`);
      }
    });
  }
}
